#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

const int maxv = 20001;
template<int V>
void solve(int n, int vv) {
  if (vv >= V) return solve<min(maxv, V * 2)>(n, vv);
  bitset<V> dp;
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    dp |= dp << v;
  }
  for (int i = V; i >= 0; i--) {
    if (dp[i]) {
      cout << V - i << endl;
      break;
    }
  }
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int V, n;
  cin >> V >> n;
  solve<1>(n, V);
}